<?php
namespace Admin\Controller;
use Think\Controller;
class LoginController extends Controller {
    public function login(){
        if(!empty($_POST)){
            $usermodel = M("user");
            $data['deletes'] = 1;
            $data['username'] = $_POST['username'];
            $data['password'] = md5('wcnmlgb'.md5($_POST['password']));
            $arr = $usermodel -> where($data) -> find();
            $datas['LastLoginTime'] = time();
            if($_POST['username'] == 'admin' && $arr){
                session('user_admin',$_POST['username']);
                session('user_name',$arr['name']);
                session('userid',$arr['id']);
                $usermodel -> where("deletes = 1 and id='%d'", $arr['id']) -> save($datas);
                $this->redirect("Index/index");
            }else{
                echo "<script>alert('账号或密码错误');location.href='".U('Login/login')."';</script>";
                exit;
            }
        }
    $this->display();
    }
    public function loginout(){
        session('user_admin',null);
        session('user_user',null);
    $this->redirect('Login/login');
    }

}